// Manage the window, the resolution, etc...


#ifndef LIGHTY_WINDOW_HANDLER_H 
#define LIGHTY_WINDOW_HANDLER_H

#include <SDL.h>
#include <GL/glew.h>
#include "Lighty_Debug.h"

SDL_Window* window=NULL;
SDL_Renderer *renderer = NULL;

int Lighty_NewWindow(int width, int height){

  if(window!=NULL){
  
    Lighty_PrintDebug("Window error : A window is already open !");
    return 1;
  
  }
  
  window=SDL_CreateWindow("Lighty", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  
  if(window==NULL){
        
    Lighty_PrintDebug("Window error : Cant create the window for some reason !");
    return 1;
        
  }
  
  SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
  renderer=SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE); // Les flags devraient pouvoir être changé dans le future.
  
  if(renderer==NULL){
        
    Lighty_PrintDebug("Window error : Cant create the renderer !");
    return 1;
        
  }
  
  GLenum glew_status=glewInit();
	
  if(glew_status!=GLEW_OK){
  
    Lighty_PrintDebug("Window error : Cant call glew !");
	return 1;
		
  }
  
  return 0;

}

void Lighty_ResizeWindow(int width, int height){
  
  SDL_SetWindowSize(window, width, height);
  SDL_RenderPresent(renderer);

}

void Lighty_CloseWindow(){

  SDL_DestroyWindow(window);
  SDL_DestroyRenderer(renderer); 
  window=NULL;
  renderer=NULL;

}

#endif
